package Calculator;
public class NewClass_Nbl implements Interface_Nbl{
    private int count=0;
    private int step=-1;
    private int end=-1;
    
    public void getEnd(int End){
        if(End==1)
            this.count=0;
        else end=-1;
    }
    public String getNumber(String str){
    String info="";
    step=-1;
    if(count>=str.length())
        return ""+"error";
    if(count<str.length()&&(str.charAt(count)=='('||str.charAt(count)==')'))
        return ""+str.charAt(count++);
    if(count<str.length()&&str.charAt(count)=='-'){
        if(count==0){
            info+=str.charAt(count++);
            while(count<str.length()&&str.charAt(count)>='0'&&str.charAt(count)<='9'){
                info+=str.charAt(count++);
                if(count<str.length()&&str.charAt(count)=='.'){
                info+=".";
                count++;
        }
    } 
            return info;  
        }
        else{
            int a=count;
            if(a>1&&str.charAt(a-1)=='('){
                 info+=str.charAt(count++);
            while(count<str.length()&&str.charAt(count)>='0'&&str.charAt(count)<='9'){
                info+=str.charAt(count++);
                if(count<str.length()&&str.charAt(count)=='.'){
                info+=".";
                count++;
        }
    } 
            }
            else  return ""+str.charAt(count++);
            return info;
        }
    }
    while(count<str.length()&&str.charAt(count)>='0'&&str.charAt(count)<='9'){
        step=0;
        info+=str.charAt(count++);
        if(count<str.length()&&str.charAt(count)=='.'){
            info+=".";
            count++;
        }
    }
    if(count<str.length()&&step==-1&&(str.charAt(count)=='+'||str.charAt(count)=='-'||str.charAt(count)=='*'||str.charAt(count)=='/'||str.charAt(count)=='%')){
        if(count!=str.length()-1)
            return ""+str.charAt(count++);
        else 
            throw new IllegalArgumentException("Error");
    }
    return info;
    }
}
